#pragma once
#include "../Header/Health.h"

using namespace std;

Health::Health(int inputMaxHP, int inputHP, int inputMinHP, GameObject* inputParent)	//This is the constructor method
{
	parent = inputParent;																//Set the parent of this GameObject to the input
	ID = "Health";																		//This component is a Health component
	this->setHealth(inputMaxHP, inputHP, inputMinHP);									//Set the relevant Health stats based on the inputs
}

void Health :: setHealth(int inputMaxHP, int inputHP, int inputMinHP)	//This method sets the Health stats to the inputs
{
	try
	{
		if(this == NULL) throw 1;
	}
	catch(int e)
	{
		cout << "Error: this \"Health\" component doesn't exist... "<<endl;
	}
	hp = inputHP;
	maxhp = inputMaxHP;
	minhp = inputMinHP;
	if(inputHP>inputMaxHP)
	{
		cout << "Error: the inputHP is greater than the inputMaxHP"<<endl;
		hp = maxhp;
	}
	if(inputHP < inputMinHP)
	{
		cout << "Error: the inputHP is less than the inputMinHP"<<endl;
		hp = minhp;
	}
	if(inputMaxHP < inputMinHP)
	{
		cout << "Error: the inputMaxHP is less than the inputMinHP"<<endl;
		inputMaxHP = inputMinHP;
	}
}

void Health :: addHealth(int amountofHealth)		//This method adds Health to hp
{
	try
	{
		if(this == NULL) throw 1;
	}
	catch(int e)
	{
		cout << "Error: this \"Health\" component doesn't exist... "<<endl;
	}

	if(amountofHealth + hp <= maxhp)				//If the new amount of Health would be less than or equal to the maxhp
	{
		hp = hp + amountofHealth;					//set the hp to that new amount of Health
	}
	else											//If the new amount of Health would overshoot the max
	{
		hp = maxhp;									//set the hp to the max amount
	}
}

void Health :: removeHealth(int amountofdamage)		//This method removes Health from hp
{
	try
	{
		if(this == NULL) throw 1;
	}
	catch(int e)
	{
		cout << "Error: this \"Health\" component doesn't exist... "<<endl;
	}

	if(hp - amountofdamage >= minhp)				//If the new amount of Health would be greater than or equal to the minhp
	{
		hp = hp - amountofdamage;					//set the hp to that new amount of Health
	}
	else											//If the new amount of Health would overshoot the min
	{
		hp = minhp;									//set the hp to the min amount
	}
}

int Health :: getHealth()							//This method returns the current hp
{
	try
	{
		if(this == NULL) throw 1;
	}
	catch(int e)
	{
		cout << "Error: this \"Health\" component doesn't exist... "<<endl;
	}
	return hp;
}

int Health ::getMaxHealth()							//This method returns the maximum hp
{
	try
	{
		if(this == NULL) throw 1;
	}
	catch(int e)
	{
		cout << "Error: this \"Health\" component doesn't exist... "<<endl;
	}
	return maxhp;
}

int Health::getMinHealth()							//This method returns the minimum hp
{
	try
	{
		if(this == NULL) throw 1;
	}
	catch(int e)
	{
		cout << "Error: this \"Health\" component doesn't exist... "<<endl;
	}
	return minhp;
}